<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @property bool $status 状态:1=待审核,2=成功,3=驳回
 * @property float $money 余额
 * @property int $city_id 城市
 * @property int $id
 * @property int $pid 上级
 * @property int $user_id 用户
 * @property string $address 详细地址
 * @property string $content 商家介绍
 * @property string $createtime
 * @property string $image 门头照
 * @property string $images 更多照片
 * @property string $lat 纬度
 * @property string $lng 经度
 * @property string $mobile 商家手机号
 * @property string $name 商家名称
 * @property string $opentime 营业时间
 * @property string $password 支付密码
 * @property string $reason 驳回原因
 * @property-read \app\model\User $parent
 * @property-read \app\model\User $user
 * @property-read \app\model\UserCollect $user_collect
 * @mixin \think\Model
 */
class Shop extends Model
{
    protected $createTime = 'createtime';
	
	protected $append = [
		'images_text'
	];
	
	function getImagesTextAttr($value,$data)
	{
		$value = $value ?? ($data['images'] ?? '');
		return $value?explode(',', $value):[];
	}
	
	
	public function userCollect()
	{
		return $this->hasOne(UserCollect::class,'pro_id')->where(['type'=>3]);
	}
	
	function parent()
	{
		return $this->belongsTo(User::class,'pid');
	}
	
	function user()
	{
		return $this->belongsTo(User::class,'user_id');
	}
	
}
